package main

import (
	"MqttCloudProtocolServer/publiclib/helplib"
	"fmt"
	"strconv"
)

// go get github.com/yuin/gopher-lua
func testFunc(calback func(float64) ([]uint16, error), checkFunc func([]uint16) (float32, error), data float64) {
	res, err := calback(data)
	if err != nil {
		fmt.Println("转换异常：" + err.Error())
		return
	}
	res2, err := checkFunc(res)
	if err != nil {
		fmt.Println("反向转换异常：" + err.Error())
		return
	}
	fmt.Printf("原数据：%f,转换回来之后：%f\r\n", data, res2)
}
func getarray() []uint16 {
	return nil
}
func main() {
	bbbb := getarray()
	if bbbb == nil {
		fmt.Println("nil")
	}
	if len(bbbb) == 0 {
		fmt.Println("0")
	}
	tempChan := make(chan int, 5)
	input := func() {
		tempChan <- 1
		fmt.Println("input 1")
		tempChan <- 2
		fmt.Println("input 2")
		tempChan <- 3
		fmt.Println("input 3")
		tempChan <- 4
		fmt.Println("input 4")
		tempChan <- 5
		fmt.Println("input 5")
		tempChan <- 6
		fmt.Println("input 6")
		tempChan <- 7
		fmt.Println("input 7")
		tempChan <- 8
		fmt.Println("input 8")
	}
	go input()
	res, flag := helplib.ReadChannelInTimeMS(&tempChan, 1)
	if flag {
		fmt.Println("读取成功:" + strconv.Itoa(*res))
	}
	helplib.ClearChannelInTimeMS(&tempChan, 1)
	helplib.ClearChannelInTimeMS(&tempChan, 1)
	res, flag = helplib.ReadChannelInTimeMS(&tempChan, 1)
	if flag {
		fmt.Println("读取成功:" + strconv.Itoa(*res))
	}

	tempFun1 := helplib.Float64ToUShortsBeByF32
	tempfun2 := helplib.UShortsToReal32Be
	testFunc(tempFun1, tempfun2, 455374553745537.7428)
	testFunc(tempFun1, tempfun2, -45537.7428)
	testFunc(tempFun1, tempfun2, 4553731013.7428)
	testFunc(tempFun1, tempfun2, -31013.7428)
	testFunc(tempFun1, tempfun2, 68000.7428)
	testFunc(tempFun1, tempfun2, -1)
	testFunc(tempFun1, tempfun2, 31013.7428)
	testFunc(tempFun1, tempfun2, 2.7428)

	tempFun1 = helplib.Float64ToUShortsLeByF32
	tempfun2 = helplib.UShortsToReal32Le
	testFunc(tempFun1, tempfun2, 455374553745537.7428)
	testFunc(tempFun1, tempfun2, -45537.7428)
	testFunc(tempFun1, tempfun2, 4553731013.7428)
	testFunc(tempFun1, tempfun2, -31013.7428)
	testFunc(tempFun1, tempfun2, 68000.7428)
	testFunc(tempFun1, tempfun2, -1)
	testFunc(tempFun1, tempfun2, 31013.7428)
	testFunc(tempFun1, tempfun2, 2.7428)
	//testSqlite()
	//return
	/*i := 0
	if manager.GetCommandCallbackHandle == nil {
		manager.GetCommandCallbackHandle = func(name *string, cmd *manager.CMDStruct) {
			println("Command call:" + *name)
			if cmd != nil {
				i++
				cmd.Command = "Command"
				cmd.Name = "VN060"
				cmd.Param = ""
				if i == 10 {
					cmd.Command = "STOP"
					cmd.Name = *name
					cmd.Param = ""
				}
			}
			return
		}
	}
	if manager.GetInfoCallbackHandle == nil {
		manager.GetInfoCallbackHandle = func(cmd *manager.CMDStruct, res *manager.ResponseStruct) {
			println("Info call:" + cmd.Name)
			println(cmd.Command)
			println(cmd.Param)
			if res != nil {
				res.Name = "lossage"
				res.Response = "what?"
				res.Result = "OK"
			}
			return
		}
	}
	server := new(manager.RPCServerManager)
	server.Start()

	cmdLine := ""
	for strings.ToUpper(cmdLine) != "EXIT" {
		//logger.Info(cmdLine)
		fmt.Scanln(&cmdLine)
	}*/
	//mainTest()
	//testChan()
	//testQueue()
	//testLua()
	//testWeb()
	//testExec()
	/*for {
		p := make([]byte, 8192)

		fmt.Println("send")
		stdin.Write([]byte("abc\r\n"))
		time.Sleep(time.Microsecond * 10)
		fmt.Println("read")
		i, _ := stdout.Read(p)
		fmt.Println(string(p[:i]))
		time.Sleep(time.Second * 1)
	}*/
}
